package com.zdxlz.fcmp.common.security.util;

import com.zdxlz.fcmp.common.core.util.JsonUtil;
import com.zdxlz.fcmp.common.core.util.R;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author: aman
 * @className ResponseUtil
 * @date 2025/2/6 15:45
 * @description
 */

public class ResponseUtil {
    public static void sendErrorResponse(HttpServletResponse response, R<?> result) {
        response.setStatus(HttpStatus.OK.value());
        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);

        try (PrintWriter writer = response.getWriter()) {
            writer.write(JsonUtil.toJson(result));
            writer.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
